package com.example.service.impl;

import com.example.dao.NoticeDao;
import com.example.dao.impl.NoticeDaoImpl;
import com.example.model.Notice;
import com.example.service.NoticeService;
import com.example.vo.Page;
import java.util.Map;

public class NoticeServiceImpl implements NoticeService {
    @Override
    public Page<Notice> getPage(Map<String, String> params) {
        Page<Notice> page = new Page<>();
        NoticeDao noticeDao = new NoticeDaoImpl();
        page.setRecords(noticeDao.getNoticesByCondition(params));
        page.setCount(noticeDao.getTotal(params));
        page.setPageSize(Integer.parseInt(params.get("pageSize")));
        return page;
    }

    @Override
    public int deleteMany(String ids) {
        NoticeDao noticeDao = new NoticeDaoImpl();
        try {
            if(ids!= null && ids.contains(",")){ //1,2,
                String[] strs = ids.split(","); //1 2 ''
                for (int i= 0; i<strs.length-1; i++) {
                   int id = Integer.parseInt(strs[i]);
                    noticeDao.deleteById(id);
                }
            }
            return 1;
        } catch (NumberFormatException e) {
            e.printStackTrace();
        }
        return 0;
    }
}
